
package com.tools.cleanmaster.utils;

import android.app.ActivityManager;
import android.content.Context;
import android.os.Build;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;

public class DevicesUtils {
    static int memoryMB = -1;

    static long sPhysicalMemory = 0L;

    static int sHeapSize = -1;

    static String deviceDesc = null;

    private static Boolean isHuaweiC8812E = null;

    private static Boolean isHuaweiU8825D = null;

    static Boolean isSamsungGalaxyNote = null;

    static Boolean isHtcG14 = null;

    static Boolean isI9100 = null;

    static Boolean isZTEModernDevice = null;

    public static boolean legacyDevices() {
        return Build.VERSION.SDK_INT <= 10;
    }

    public static boolean modernDevices() {
        return Build.VERSION.SDK_INT > 10;
    }

    public static boolean lowPhysicalMemoryDevices() {
        if (memoryMB == -1) {
            memoryMB = (int) (getPhysicalMemoryKBs().longValue() / 1024L);
        }
        return memoryMB < 300;
    }

    public static Long getPhysicalMemoryKBs() {
        if (sPhysicalMemory == 0L) {
            String PATTERN = "MemTotal:";

            InputStream inStream = null;
            InputStreamReader inReader = null;
            BufferedReader inBuffer = null;
            try {
                inStream = new FileInputStream("/proc/meminfo");
                inReader = new InputStreamReader(inStream);
                inBuffer = new BufferedReader(inReader);
                String s;
                while (((s = inBuffer.readLine()) != null) && (s.length() > 0))
                    if (s.startsWith("MemTotal:")) {
                        String memKBs = s.substring("MemTotal:".length()).trim();
                        memKBs = memKBs.substring(0, memKBs.indexOf(' '));
                        sPhysicalMemory = Long.parseLong(memKBs);
                    }
            } catch (Exception e) {
            } finally {
                Utilities.silentlyClose(inStream);
                Utilities.silentlyClose(inReader);
                Utilities.silentlyClose(inBuffer);
            }
        }

        return Long.valueOf(sPhysicalMemory);
    }

    public static boolean extremeLowMemoryDevices() {
        return getHeapSize() <= 20;
    }

    public static boolean lowMemoryDevices() {
        return getHeapSize() < 30;
    }

    public static int getHeapSize() {
        if (sHeapSize <= 0) {
            ActivityManager am = (ActivityManager) Utilities.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);

            sHeapSize = am.getMemoryClass();
        }
        return sHeapSize;
    }

    public static String getDeviceDescription() {
        if (deviceDesc == null) {
            StringBuffer sb = new StringBuffer();

            sb.append('\n');
            sb.append('\t').append("Build.MANUFACTURER\t").append(Build.MANUFACTURER).append('\n');
            sb.append('\t').append("Build.MODEL\t").append(Build.MODEL).append('\n');
            sb.append('\t').append("Build.PRODUCT\t").append(Build.PRODUCT).append('\n');
            sb.append('\t').append("Build.DEVICE\t").append(Build.DEVICE).append('\n');
            sb.append('\t').append("Build.BOARD\t").append(Build.BOARD).append('\n');
            sb.append('\t').append("Build.BRAND\t").append(Build.BRAND).append('\n');
            sb.append('\t').append("Build.CPU_ABI\t").append(Build.CPU_ABI).append('\n');
            sb.append('\t').append("Build.DISPLAY\t").append(Build.DISPLAY).append('\n');
            sb.append('\t').append("Build.FINGERPRINT\t").append(Build.FINGERPRINT).append('\n');
            if (Build.VERSION.SDK_INT >= 8) {
                sb.append('\t').append("Build.HARDWARE\t").append(Build.HARDWARE).append('\n');
                sb.append('\t').append("Build.RADIO\t").append(Build.RADIO).append('\n');
            }
            if (Build.VERSION.SDK_INT >= 9) {
                sb.append('\t').append("Build.SERIAL\t").append(Build.SERIAL).append('\n');
            }
            sb.append('\t').append("Build.TAGS\t").append(Build.TAGS).append('\n');
            sb.append('\t').append("Build.TYPE\t").append(Build.TYPE).append('\n');
            sb.append('\t').append("Build.SDK_INT\t").append(Build.VERSION.SDK_INT).append('\n');

            deviceDesc = sb.toString();
        }

        return deviceDesc;
    }

    public static boolean isMeizuM9() {
        String fingerprint = Build.FINGERPRINT;
        return fingerprint.indexOf("meizu_m9") != -1;
    }

    public static boolean isHuaweiC8812E() {
        if (isHuaweiC8812E == null) {
            String fingerPrint = Build.FINGERPRINT;
            isHuaweiC8812E = Boolean.valueOf(fingerPrint != null && fingerPrint.contains("HuaweiC8812E"));
        }
        return isHuaweiC8812E.booleanValue();
    }

    public static boolean isHuaweiU8825D() {
        if (isHuaweiU8825D == null) {
            String fingerPrint = Build.FINGERPRINT;
            isHuaweiU8825D = Boolean.valueOf(fingerPrint != null && fingerPrint.contains("HuaweiU8825D"));
        }
        return isHuaweiU8825D.booleanValue();
    }

    public static boolean isGalaxyNote() {
        if (isSamsungGalaxyNote == null) {
            String FINGERPRINT = "samsung/GT-N7000/GT-N7000:2.3.5/GINGERBREAD/ZSKJ6:user/release-keys";
            String MODEL = "GT-N7000";
            if ((Build.FINGERPRINT.equals("samsung/GT-N7000/GT-N7000:2.3.5/GINGERBREAD/ZSKJ6:user/release-keys")) || (Build.FINGERPRINT.contains("GT-N7000"))) {
                isSamsungGalaxyNote = Boolean.valueOf(true);
            } else {
                isSamsungGalaxyNote = Boolean.valueOf(false);
            }
        }

        return isSamsungGalaxyNote.booleanValue();
    }

    public static boolean isHtcG14() {
        if (isHtcG14 == null) {
            String FINGERPRINT = "htccn_chs_cu/htc_pyramid/pyramid:4.0.3/IML74K/357408.14:user/release-keys";
            if (Build.FINGERPRINT.equals("htccn_chs_cu/htc_pyramid/pyramid:4.0.3/IML74K/357408.14:user/release-keys")) {
                isHtcG14 = Boolean.valueOf(true);
            } else {
                isHtcG14 = Boolean.valueOf(false);
            }
        }

        return isHtcG14.booleanValue();
    }

    public static boolean isI9100() {
        if (isI9100 == null) {
            String FINGERPRINT = "samsung/GT-I9100/GT-I9100:4.0.3/IML74K/ZSLPE:user/release-keys";
            String MODEL = "GT-I9100";
            if ((Build.FINGERPRINT.equals("samsung/GT-I9100/GT-I9100:4.0.3/IML74K/ZSLPE:user/release-keys")) || (Build.FINGERPRINT.contains("GT-I9100"))) {
                isI9100 = Boolean.valueOf(true);
            } else {
                isI9100 = Boolean.valueOf(false);
            }
        }
        return isI9100.booleanValue();
    }

    public static boolean isZTEModernDevice() {
        if (isZTEModernDevice == null) {
            String MODEL = "ZTE";
            if (((modernDevices()) && (Build.FINGERPRINT.contains("ZTE"))) || (Build.MODEL.contains("ZTE"))) {
                isZTEModernDevice = Boolean.valueOf(true);
            } else {
                isZTEModernDevice = Boolean.valueOf(false);
            }
        }
        return isZTEModernDevice.booleanValue();
    }
}
